﻿Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

Module UIHelper

    ' 给任意控件设置四角圆角
    Public Sub SetControlRound(ctrl As Control, radius As Integer)
        Dim path As New GraphicsPath()
        Dim rect As Rectangle = New Rectangle(0, 0, ctrl.Width, ctrl.Height)
        Dim d As Integer = radius * 2

        path.StartFigure()
        path.AddArc(New Rectangle(rect.X, rect.Y, d, d), 180, 90) ' 左上角
        path.AddArc(New Rectangle(rect.Right - d, rect.Y, d, d), 270, 90) ' 右上角
        path.AddArc(New Rectangle(rect.Right - d, rect.Bottom - d, d, d), 0, 90) ' 右下角
        path.AddArc(New Rectangle(rect.X, rect.Bottom - d, d, d), 90, 90) ' 左下角
        path.CloseFigure()

        ctrl.Region = New Region(path)
    End Sub
End Module
